home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / a3drot1a / 3dspin.frm (.txt) next >
Encoding:
Visual Basic Form  |  1999-10-18  |  22.5 KB  |  536 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Form1"
  5.    ClientHeight    =   5910
  6.    ClientLeft      =   2625
  7.    ClientTop       =   5070
  8.    ClientWidth     =   10380
  9.    FillStyle       =   0  'Solid
  10.    ForeColor       =   &H00000000&
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   5910
  13.    ScaleWidth      =   10380
  14.    Begin VB.PictureBox Pic3D 
  15.       AutoRedraw      =   -1  'True
  16.       FillStyle       =   0  'Solid
  17.       ForeColor       =   &H00000000&
  18.       Height          =   2400
  19.       Left            =   2760
  20.       ScaleHeight     =   2340
  21.       ScaleWidth      =   2340
  22.       TabIndex        =   17
  23.       Top             =   360
  24.       Width           =   2400
  25.    End
  26.    Begin VB.PictureBox PicSTB 
  27.       AutoRedraw      =   -1  'True
  28.       FillStyle       =   0  'Solid
  29.       Height          =   2400
  30.       Left            =   7800
  31.       ScaleHeight     =   2340
  32.       ScaleWidth      =   2340
  33.       TabIndex        =   15
  34.       Top             =   3120
  35.       Width           =   2400
  36.    End
  37.    Begin VB.PictureBox PicFTB 
  38.       AutoRedraw      =   -1  'True
  39.       FillStyle       =   0  'Solid
  40.       Height          =   2400
  41.       Left            =   7800
  42.       ScaleHeight     =   2340
  43.       ScaleWidth      =   2340
  44.       TabIndex        =   13
  45.       Top             =   360
  46.       Width           =   2400
  47.    End
  48.    Begin VB.CommandButton BUTNStop 
  49.       Caption         =   "Stop"
  50.       Height          =   255
  51.       Left            =   240
  52.       TabIndex        =   9
  53.       Top             =   1560
  54.       Width           =   1935
  55.    End
  56.    Begin VB.CommandButton BUTNStart 
  57.       Caption         =   "Start"
  58.       Height          =   255
  59.       Left            =   240
  60.       TabIndex        =   8
  61.       Top             =   1200
  62.       Width           =   1935
  63.    End
  64.    Begin VB.CommandButton BUTNReset 
  65.       Caption         =   "Reset"
  66.       Height          =   255
  67.       Left            =   240
  68.       TabIndex        =   7
  69.       Top             =   1920
  70.       Width           =   1935
  71.    End
  72.    Begin VB.PictureBox PicTop 
  73.       AutoRedraw      =   -1  'True
  74.       FillStyle       =   0  'Solid
  75.       Height          =   2400
  76.       Left            =   5280
  77.       ScaleHeight     =   2340
  78.       ScaleWidth      =   2340
  79.       TabIndex        =   6
  80.       Top             =   3120
  81.       Width           =   2400
  82.    End
  83.    Begin VB.Timer Timer1 
  84.       Enabled         =   0   'False
  85.       Interval        =   50
  86.       Left            =   4560
  87.       Top             =   2760
  88.    End
  89.    Begin VB.CommandButton BUTNQuit 
  90.       Caption         =   "Quit"
  91.       Height          =   255
  92.       Left            =   240
  93.       TabIndex        =   4
  94.       Top             =   2280
  95.       Width           =   1935
  96.    End
  97.    Begin VB.CommandButton BUTNOKAY 
  98.       Caption         =   "Move"
  99.       Height          =   255
  100.       Left            =   240
  101.       TabIndex        =   3
  102.       Top             =   840
  103.       Width           =   1935
  104.    End
  105.    Begin VB.TextBox TEXTAngle 
  106.       Height          =   285
  107.       Left            =   1320
  108.       TabIndex        =   2
  109.       Top             =   360
  110.       Width           =   855
  111.    End
  112.    Begin VB.PictureBox PicFRL 
  113.       AutoRedraw      =   -1  'True
  114.       FillStyle       =   0  'Solid
  115.       Height          =   2400
  116.       Left            =   5280
  117.       ScaleHeight     =   2340
  118.       ScaleWidth      =   2340
  119.       TabIndex        =   1
  120.       Top             =   360
  121.       Width           =   2400
  122.    End
  123.    Begin VB.PictureBox PicXY 
  124.       AutoRedraw      =   -1  'True
  125.       FillStyle       =   0  'Solid
  126.       Height          =   2400
  127.       Left            =   2760
  128.       ScaleHeight     =   2340
  129.       ScaleWidth      =   2340
  130.       TabIndex        =   0
  131.       Top             =   3120
  132.       Width           =   2400
  133.    End
  134.    Begin VB.Label Label17 
  135.       Caption         =   "3D rotation"
  136.       Height          =   255
  137.       Left            =   2760
  138.       TabIndex        =   18
  139.       Top             =   120
  140.       Width           =   2295
  141.    End
  142.    Begin VB.Label Label16 
  143.       Caption         =   "Side, Top to Bottom Rotation"
  144.       Height          =   255
  145.       Left            =   7800
  146.       TabIndex        =   16
  147.       Top             =   2880
  148.       Width           =   2295
  149.    End
  150.    Begin VB.Label Label15 
  151.       Caption         =   "Front, Top to Bottom Rotation"
  152.       Height          =   255
  153.       Left            =   7800
  154.       TabIndex        =   14
  155.       Top             =   120
  156.       Width           =   2295
  157.    End
  158.    Begin VB.Label Label14 
  159.       Caption         =   "Top, Right to Left Rotation"
  160.       Height          =   255
  161.       Left            =   5280
  162.       TabIndex        =   12
  163.       Top             =   2880
  164.       Width           =   2295
  165.    End
  166.    Begin VB.Label Label13 
  167.       Caption         =   "Front, Right to Left Rotation"
  168.       Height          =   255
  169.       Left            =   5280
  170.       TabIndex        =   11
  171.       Top             =   120
  172.       Width           =   2295
  173.    End
  174.    Begin VB.Label Label11 
  175.       Caption         =   "Front, Stationary"
  176.       Height          =   255
  177.       Left            =   2760
  178.       TabIndex        =   10
  179.       Top             =   2880
  180.       Width           =   1575
  181.    End
  182.    Begin VB.Label Label12 
  183.       Caption         =   "Current Angle:"
  184.       Height          =   255
  185.       Left            =   240
  186.       TabIndex        =   5
  187.       Top             =   360
  188.       Width           =   1095
  189.    End
  190. Attribute VB_Name = "Form1"
  191. Attribute VB_GlobalNameSpace = False
  192. Attribute VB_Creatable = False
  193. Attribute VB_PredeclaredId = True
  194. Attribute VB_Exposed = False
  195. Dim Angle As Double             'The rotation angle
  196. Dim AngleHolder As Double       'holder for previous rotation angle
  197. Dim NumObjectSides As Integer   'Number of sides making up the object
  198. Private Type Point              'The makeup of a point
  199.     X As Double                 'the X location of the point
  200.     Y As Double                 'the Y location of the point
  201.     Z As Double                 'the Z location of the point
  202. End Type
  203. Dim Center As Point             'center of the picboxes
  204. Private Type Verticies          'The verticies of a side
  205.     NumPoints As Integer        'The number of points on a line
  206.     Points(20) As Point         'the actual endpoints of each line
  207.     Normal As Point             'The normal of the Plane
  208. End Type
  209. Dim Sides(50) As Verticies      'the sides of the object
  210. Dim XSides(50) As Verticies     'the X rotation points
  211. Dim YSides(50) As Verticies     'the Y rotation points
  212. Dim ZSides(50) As Verticies     'the Z rotation points
  213. Dim Sides3D(50) As Verticies    'the 3D rotation of points
  214. Dim CosAng(359) As Double       'A lookup table to hold the Cosine Angles
  215. Dim SinAng(359) As Double       'A lookup table to hold the Sine Angles
  216. Private Type POINTAPI           'This is the drawn Points of the
  217.   X As Long                     'object to fill it and draw it fast
  218.   Y As Long                     'using a win api function
  219. End Type
  220. Dim tmp() As POINTAPI
  221. 'This function is for drawing filled polygons Much faster than anything I wrote
  222. Private Declare Function Polygon Lib "gdi32" _
  223.   (ByVal hdc As Long, lpPoint As POINTAPI, ByVal nCount As Long) As Long
  224. Private Sub BUTNOKAY_Click()
  225.     'set the angle and draw the rotation
  226.     AngleHolder = AngleHolder + 5       'increment the angle
  227.     If AngleHolder = 360 Then           'reset the angle back to 0
  228.         AngleHolder = 0
  229.     End If
  230.         
  231.     TEXTAngle.Text = AngleHolder        'display the current angle
  232.     Angle = AngleHolder                 'Set the angle for calculations
  233.     Redraw                              'refresh the display
  234. End Sub
  235. Private Sub BUTNQuit_Click()
  236.     End                                 'end the program
  237. End Sub
  238. Private Sub BUTNReset_Click()
  239.     AngleHolder = 355                   'reset so displayed angle will be 0
  240.     BUTNOKAY_Click                      'set angles and displays, then redraw
  241. End Sub
  242. Private Sub BUTNStart_Click()
  243.     Timer1.Enabled = True               'start the autodraw timer
  244. End Sub
  245. Private Sub BUTNStop_Click()
  246.     Timer1.Enabled = False              'stop the auto draw timer
  247. End Sub
  248. Private Sub Form_Load()
  249.     'Form1.ScaleMode = vbTwips
  250.     Angle = 0                           'initialize the angles
  251.     AngleHolder = 355
  252.     Center.X = Pic3D.Width / 2          'set the centers (all coordinates for the picboxes must be equal
  253.     Center.Y = Pic3D.Height / 2         'acroos picboxes for this to work)(i.e. the X dimension in left
  254.     Center.Z = Pic3D.Width / 2          'to right picbox must equal X dimension in top to bottom picbox)
  255.     'set points for rectangle (could be done in a better way loop etc.)
  256.     'Also shape does not have to be rectangle can be any shape
  257.     'front
  258.     Sides(0).Points(0).X = -20: Sides(0).Points(0).Y = -50: Sides(0).Points(0).Z = 20
  259.     Sides(0).Points(1).X = 50: Sides(0).Points(1).Y = -50: Sides(0).Points(1).Z = 20
  260.     Sides(0).Points(2).X = 50: Sides(0).Points(2).Y = 50: Sides(0).Points(2).Z = 20
  261.     Sides(0).Points(3).X = -20: Sides(0).Points(3).Y = 50: Sides(0).Points(3).Z = 20
  262.     'back
  263.     Sides(1).Points(0).X = 50: Sides(1).Points(0).Y = -50: Sides(1).Points(0).Z = -20
  264.     Sides(1).Points(1).X = -20: Sides(1).Points(1).Y = -50: Sides(1).Points(1).Z = -20
  265.     Sides(1).Points(2).X = -20: Sides(1).Points(2).Y = 50: Sides(1).Points(2).Z = -20
  266.     Sides(1).Points(3).X = 50: Sides(1).Points(3).Y = 50: Sides(1).Points(3).Z = -20
  267.     'Top
  268.     Sides(2).Points(0).X = -20: Sides(2).Points(0).Y = -50: Sides(2).Points(0).Z = -20
  269.     Sides(2).Points(1).X = 50: Sides(2).Points(1).Y = -50: Sides(2).Points(1).Z = -20
  270.     Sides(2).Points(2).X = 50: Sides(2).Points(2).Y = -50: Sides(2).Points(2).Z = 20
  271.     Sides(2).Points(3).X = -20: Sides(2).Points(3).Y = -50: Sides(2).Points(3).Z = 20
  272.     'bottom
  273.     Sides(3).Points(0).X = -20: Sides(3).Points(0).Y = 50: Sides(3).Points(0).Z = 20
  274.     Sides(3).Points(1).X = 50: Sides(3).Points(1).Y = 50: Sides(3).Points(1).Z = 20
  275.     Sides(3).Points(2).X = 50: Sides(3).Points(2).Y = 50: Sides(3).Points(2).Z = -20
  276.     Sides(3).Points(3).X = -20: Sides(3).Points(3).Y = 50: Sides(3).Points(3).Z = -20
  277.     'Lside
  278.     Sides(4).Points(0).X = -20: Sides(4).Points(0).Y = -50: Sides(4).Points(0).Z = -20
  279.     Sides(4).Points(1).X = -20: Sides(4).Points(1).Y = -50: Sides(4).Points(1).Z = 20
  280.     Sides(4).Points(2).X = -20: Sides(4).Points(2).Y = 50: Sides(4).Points(2).Z = 20
  281.     Sides(4).Points(3).X = -20: Sides(4).Points(3).Y = 50: Sides(4).Points(3).Z = -20
  282.     'Rside
  283.     Sides(5).Points(0).X = 50: Sides(5).Points(0).Y = -50: Sides(5).Points(0).Z = 20
  284.     Sides(5).Points(1).X = 50: Sides(5).Points(1).Y = -50: Sides(5).Points(1).Z = -20
  285.     Sides(5).Points(2).X = 50: Sides(5).Points(2).Y = 50: Sides(5).Points(2).Z = -20
  286.     Sides(5).Points(3).X = 50: Sides(5).Points(3).Y = 50: Sides(5).Points(3).Z = 20
  287.     'set the number of edges for each side
  288.     For i = 0 To 5
  289.         Sides(i).NumPoints = 3
  290.     Next i
  291.     'set the number of sides the object has
  292.     NumObjectSides = 5
  293.     'Calculate the Normals
  294.     FindNormals
  295.     'Create the Lookup table for the Cos and Sin functions.
  296.     'This method is much faster than calculating each step
  297.     CreateTables
  298.     'set angles and displays, then redraw
  299.     BUTNOKAY_Click
  300. End Sub
  301. Sub Redraw()
  302.     'clear the picboxes
  303.     PicXY.Cls
  304.     PicFRL.Cls
  305.     PicTop.Cls
  306.     PicFTB.Cls
  307.     PicSTB.Cls
  308.     Pic3D.Cls
  309.       
  310.     'draw the front of the box in the stationary view
  311.     DrawShape Sides(0), PicXY, "FRONT"
  312.     'repeat loop 6 times once for each side the rotation of each point must
  313.     'be calculated to find the new position of the normal of each side to
  314.     'determine if it's visible
  315.     For j = 0 To 5
  316.         '**************************************************************
  317.         'draw the points for a top to bottom rotation (rotation around
  318.         'the X axis)
  319.         '**************************************************************
  320.         For i = 0 To Sides(0).NumPoints
  321.             XSides(j).NumPoints = Sides(0).NumPoints
  322.             
  323.             XSides(j).Points(i).X = Sides(j).Points(i).X                                                    'new x value
  324.             XSides(j).Points(i).Y = Sides(j).Points(i).Y * CosAng(Angle) - Sides(j).Points(i).Z * SinAng(Angle)   'new y value
  325.             XSides(j).Points(i).Z = Sides(j).Points(i).Z * CosAng(Angle) + Sides(j).Points(i).Y * SinAng(Angle)   'new z value
  326.             
  327.             XSides(j).Normal.X = Sides(j).Normal.X
  328.             XSides(j).Normal.Y = Sides(j).Normal.Y * CosAng(Angle) - Sides(j).Normal.Z * SinAng(Angle)   'new y value
  329.             XSides(j).Normal.Z = Sides(j).Normal.Z * CosAng(Angle) + Sides(j).Normal.Y * SinAng(Angle)   'new z value
  330.             
  331.         Next i
  332.            
  333.         'check to see if plane is visible if so draw it
  334.         If VisiblePlane(XSides(j), 0, 0, 1000) Then
  335.             'Draw lines in top, top to bottom rotation
  336.             DrawShape XSides(j), PicFTB, "FRONT"
  337.         End If
  338.         If VisiblePlane(XSides(j), 1000, 0, 0) Then
  339.             'Draw points in side, top to bottom rotation view
  340.             DrawShape XSides(j), PicSTB, "SIDE"
  341.         End If
  342.             
  343.         
  344.         
  345.         '**************************************************************
  346.         'draw the points for a left to right rotation (rotation around
  347.         'the Y axis)
  348.         '**************************************************************
  349.         
  350.         For i = 0 To Sides(0).NumPoints
  351.             YSides(j).NumPoints = Sides(0).NumPoints
  352.             
  353.             YSides(j).Points(i).X = Sides(j).Points(i).X * CosAng(Angle) + Sides(j).Points(i).Z * SinAng(Angle)   'new x value
  354.             YSides(j).Points(i).Y = Sides(j).Points(i).Y                                                    'new y value
  355.             YSides(j).Points(i).Z = Sides(j).Points(i).Z * CosAng(Angle) - Sides(j).Points(i).X * SinAng(Angle)   'new z value
  356.             
  357.             YSides(j).Normal.X = Sides(j).Normal.X * CosAng(Angle) + Sides(j).Normal.Z * SinAng(Angle)   'new x value
  358.             YSides(j).Normal.Y = Sides(j).Normal.Y                                                    'new y value
  359.             YSides(j).Normal.Z = Sides(j).Normal.Z * CosAng(Angle) - Sides(j).Normal.X * SinAng(Angle)   'new z value
  360.             
  361.         Next i
  362.         
  363.         'check to see if plane is visible if so draw it
  364.         If VisiblePlane(YSides(j), 0, 0, 1000) Then
  365.             'Draw lines in front right to left rotation view
  366.             DrawShape YSides(j), PicFRL, "FRONT"
  367.         End If
  368.         If VisiblePlane(YSides(j), 0, 1000, 0) Then
  369.         'Draw lines in top right to left rotation view
  370.             DrawShape YSides(j), PicTop, "TOP"
  371.         End If
  372.         
  373.         
  374.         '**************************************************************
  375.         'draw the points for a sideways rotation (rotation around
  376.         'the Z axis)
  377.         '**************************************************************
  378.         'Remove comments to do calculation
  379.         'Rotate Z direction
  380.         'For i = 0 To Sides(0).NumPoints
  381.         '    ZSides(j).NumPoints = Sides(0).NumPoints
  382.         '
  383.         '    ZSides(j).Points(i).X = Sides(j).Points(i).X * CosAng(Angle) + Sides(j).Points(i).Y * SinAng(Angle)   'new x value
  384.         '    ZSides(j).Points(i).Y = Sides(j).Points(i).Y * CosAng(Angle) - Sides(j).Points(i).X * SinAng(Angle)   'new y value
  385.         '    ZSides(j).Points(i).Z = Sides(j).Points(i).Z                                                    'new z value
  386.         '
  387.         '    ZSides(j).Normal.X = Sides(j).Normal.X * CosAng(Angle) + Sides(j).Normal.Y * SinAng(Angle)   'new x value
  388.         '    ZSides(j).Normal.Y = Sides(j).Normal.Y * CosAng(Angle) - Sides(j).Normal.X * SinAng(Angle)   'new y value
  389.         '    ZSides(j).Normal.Z = Sides(j).Normal.Z                                                    'new z value
  390.         '
  391.         'Next i
  392.         
  393.         
  394.         'Rotate values rotated in X direction in Z direction to make "spinning effect"
  395.         For i = 0 To Sides(0).NumPoints
  396.             Sides3D(j).NumPoints = Sides(0).NumPoints
  397.             
  398.             Sides3D(j).Points(i).X = XSides(j).Points(i).X * CosAng(Angle) + XSides(j).Points(i).Y * SinAng(Angle) 'new x value
  399.             Sides3D(j).Points(i).Y = XSides(j).Points(i).Y * CosAng(Angle) - XSides(j).Points(i).X * SinAng(Angle)  'new y value
  400.             Sides3D(j).Points(i).Z = XSides(j).Points(i).Z                                                    'new z value
  401.             
  402.             Sides3D(j).Normal.X = XSides(j).Normal.X * CosAng(Angle) + XSides(j).Normal.Y * SinAng(Angle) 'new x value
  403.             Sides3D(j).Normal.Y = XSides(j).Normal.Y * CosAng(Angle) - XSides(j).Normal.X * SinAng(Angle)  'new y value
  404.             Sides3D(j).Normal.Z = XSides(j).Normal.Z                                                    'new z value
  405.             
  406.         Next i
  407.         'check to see if plane is visible if so draw it
  408.         If VisiblePlane(Sides3D(j), 0, 1000, 0) Then
  409.             'Draw the 2 direction rotation
  410.             DrawShape Sides3D(j), Pic3D, "TOP"
  411.         End If
  412.     Next j
  413.     'draw centerpoint of each picbox in Blue
  414.     PicXY.Circle (Center.X, Center.Y), 30, RGB(0, 0, 255)
  415.     PicFRL.Circle (Center.X, Center.Y), 30, RGB(0, 0, 255)
  416.     PicTop.Circle (Center.X, Center.Y), 30, RGB(0, 0, 255)
  417.     PicFTB.Circle (Center.X, Center.Y), 30, RGB(0, 0, 255)
  418.     PicSTB.Circle (Center.X, Center.Y), 30, RGB(0, 0, 255)
  419.     Pic3D.Circle (Center.X, Center.Y), 30, RGB(0, 0, 255)
  420. End Sub
  421. Private Sub Timer1_Timer()
  422.     'rotate the rectangle
  423.     BUTNOKAY_Click
  424. End Sub
  425. Private Function DrawShape(shape As Verticies, PicBox As PictureBox, View As String)
  426.     ' add 75 to all points to center object
  427.     'determine view
  428.     If View = "FRONT" Then
  429.         'create lppoints for the win func call
  430.         ReDim tmp(shape.NumPoints) As POINTAPI
  431.         
  432.         'fill in the drawing points tmp.x as the value going in the x dir etc
  433.         For i = 0 To shape.NumPoints
  434.             tmp(i).X = shape.Points(i).X + 75
  435.             tmp(i).Y = shape.Points(i).Y + 75
  436.         Next i
  437.         
  438.         'Draw solid polygons
  439.         
  440.         'calculate light value (ambient + Max * (normal of plane * light position)
  441.         Colr = 100 + 200 * (shape.Normal.Z)
  442.         'Fill object as solid
  443.         PicBox.FillStyle = 0
  444.         'Choose the color (this way makes a shade of yellow)
  445.         PicBox.FillColor = RGB(Colr, Colr, Colr / 2)
  446.         'draw the polygon
  447.         Polygon PicBox.hdc, tmp(0), shape.NumPoints + 1
  448.         'draw rest of objects transparently
  449.         PicBox.FillStyle = 1
  450.         
  451.     ElseIf View = "TOP" Then
  452.         
  453.         'creat lppoints for the win func call
  454.         ReDim tmp(shape.NumPoints) As POINTAPI
  455.         
  456.         'fill in the drawing points tmp.x as the value going in the x dir etc
  457.         For i = 0 To shape.NumPoints
  458.             tmp(i).X = shape.Points(i).X + 75
  459.             tmp(i).Y = shape.Points(i).Z + 75
  460.         Next i
  461.         
  462.         'Draw solid polygons
  463.         
  464.         'calculate light value (ambient + Max * (normal of plane * light position)
  465.         Colr = 100 + 200 * (shape.Normal.Y)
  466.         'Fill object as solid
  467.         PicBox.FillStyle = 0
  468.         'Choose the color (this way makes a shade of yellow)
  469.         PicBox.FillColor = RGB(Colr, Colr, Colr / 2)
  470.         'draw the polygon
  471.         Polygon PicBox.hdc, tmp(0), shape.NumPoints + 1
  472.         'draw rest of objects transparently
  473.         PicBox.FillStyle = 1
  474.         
  475.         
  476.     ElseIf View = "SIDE" Then
  477.         'creat lppoints for the win func call
  478.         ReDim tmp(shape.NumPoints) As POINTAPI
  479.         
  480.         'fill in the drawing points tmp.x as the value going in the x dir etc
  481.         For i = 0 To shape.NumPoints
  482.             tmp(i).X = shape.Points(i).Z + 75
  483.             tmp(i).Y = shape.Points(i).Y + 75
  484.         Next i
  485.         
  486.         'Draw solid polygons
  487.         'calculate color value (ambient + Max * (normal of plane * light position)
  488.         Colr = 100 + 200 * (shape.Normal.X)
  489.         'Fill object as solid
  490.         PicBox.FillStyle = 0
  491.         'Choose the color (this way makes a shade of yellow)
  492.         PicBox.FillColor = RGB(Colr, Colr, Colr / 2)
  493.         'draw the polygon
  494.         Polygon PicBox.hdc, tmp(0), shape.NumPoints + 1
  495.         'draw rest of objects transparently
  496.         PicBox.FillStyle = 1
  497.         
  498.     End If
  499. End Function
  500. Private Function VisiblePlane(shape As Verticies, CameraX As Integer, CameraY As Integer, CameraZ As Integer)
  501.     'this function takes the normal of the plane and returns True if visible FALSE if
  502.     'not visible
  503.     'Camera is the spot the object is being viewed from
  504.     'Find the dot product
  505.     D = (shape.Normal.X * CameraX) + (shape.Normal.Y * CameraY) + (shape.Normal.Z * CameraZ)
  506.     'return true if object is visible
  507.     VisiblePlane = D >= 0
  508. End Function
  509. Private Function FindNormals()
  510.     'This function finds the normal of each plane
  511.     For i = 0 To NumObjectSides
  512.         'Find the normal vector
  513.         With Sides(i)
  514.             '    *                           *   *                                    *   *                           *   *                                    *
  515.             Nx = (.Points(1).Y - .Points(0).Y) * (.Points(.NumPoints).Z - .Points(0).Z) - (.Points(1).Z - .Points(0).Z) * (.Points(.NumPoints).Y - .Points(0).Y)
  516.             Ny = (.Points(1).Z - .Points(0).Z) * (.Points(.NumPoints).X - .Points(0).X) - (.Points(1).X - .Points(0).X) * (.Points(.NumPoints).Z - .Points(0).Z)
  517.             Nz = (.Points(1).X - .Points(0).X) * (.Points(.NumPoints).Y - .Points(0).Y) - (.Points(1).Y - .Points(0).Y) * (.Points(.NumPoints).X - .Points(0).X)
  518.         
  519.         
  520.             'Normalize the normal vector (make length of 1)
  521.             Length = Sqr(Nx ^ 2 + Ny ^ 2 + Nz ^ 2)
  522.             
  523.             .Normal.X = Nx / Length
  524.             .Normal.Y = Ny / Length
  525.             .Normal.Z = Nz / Length
  526.         End With
  527.     Next i
  528. End Function
  529. Private Function CreateTables()
  530.     'Create cosine and sine lookup table
  531.     For i = 0 To 359
  532.         CosAng(i) = Cos(i * (3.14159265358979 / 180)) 'convert degrees to radians
  533.         SinAng(i) = Sin(i * (3.14159265358979 / 180)) 'convert degrees to radians
  534.     Next i
  535. End Function
  536.